home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_02_07 / 2n07065b < prev    next >
Text File  |  1991-06-01  |  4KB  |  143 lines

  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <conio.h>
  4. #include "esp.h"
  5. #include "esp.fu"
  6.  
  7. #define OK     1
  8. #define FAIL   0
  9. #define bool   short
  10.  
  11. int main();
  12. short ESP_InfoReport();
  13. void DisplayAttributes();
  14.  
  15. struct attr_list {
  16.    short attr_val;      /* Bitmask value for "AND" comparison  */
  17.    char *attr_false;    /* Display this string if masked false */
  18.    char *attr_true;     /* Display this string if masked true  */
  19.       } AttrList;
  20.  
  21. struct attr_list test_attrs[] = {
  22.    { ESP_TEST_RAM_FAIL,
  23.     "RAM test OK", "RAM test FAILED" },
  24.    { ESP_TEST_ROM_FAIL,
  25.     "ROM test OK", "ROM checksum FAILED" },
  26.    { ESP_TEST_8K_ROM,
  27.     "ROM size is 4K", "ROM size is 8K" },
  28.    { ESP_TEST_MCA_BUS,
  29.     "AT ISA-compatible bus", "PS/2 MCA-compatible bus" },
  30.    { ESP_TEST_2_PORT,
  31.        "Single-port ESP interface (phantom product)",
  32.        "Dual-port ESP interface" }
  33.    };
  34.  
  35. struct attr_list mode_attrs[] = {
  36.    { ESP_MODE_ENHANCED,
  37.     "Compatibility Mode enabled", "Enhanced Mode enabled" },
  38.    { ESP_MODE_COMP_UART_FIFO,
  39.     "Compatibility Mode UART FIFO disabled",
  40.     "Compatibility Mode UART FIFO enabled" },
  41.    { ESP_MODE_COMP_RTS_FLOW,
  42.     "Compatibility Mode RTS flow control disabled",
  43.     "Compatibility Mode RTS flow control enabled" },
  44.    { ESP_MODE_COMP_DTR_FLOW,
  45.     "Compatibility Mode DTR flow control disabled",
  46.     "Compatibility Mode DTR flow control enabled" },
  47.    { ESP_MODE_ENH_RX_DMA,
  48.     "Enhanced Mode RX is Programmed I/O Mode",
  49.     "Enhanced Mode RX is Direct Memory Access Mode" },
  50.    { ESP_MODE_ENH_TX_DMA,
  51.     "Enhanced Mode TX is Programmed I/O Mode",
  52.     "Enhanced Mode TX is Direct Memory Access Mode" }
  53.    };
  54.  
  55. #define NUM_TEST_ATTRS (sizeof(test_attrs) / sizeof(AttrList))
  56. #define NUM_MODE_ATTRS (sizeof(mode_attrs) / sizeof(AttrList))
  57.  
  58. extern short esp_uart_addr[], esp_irq[];
  59.  
  60. main(argc,argv)
  61. int argc;
  62. char **argv;
  63. {
  64.    return ESP_InfoReport();
  65. }
  66.  
  67.  
  68. short ESP_InfoReport()
  69. {
  70.    ESP_Handle esp1, esp2;
  71.    short rom_rev;
  72.    short test_results;
  73.    short dips;
  74.    short def_mode;
  75.    short cur_mode;
  76.  
  77.    if (!ESP_InitHandle(&esp1, 1, 1))
  78.       return FAIL;
  79.  
  80.    if (!ESP_InitHandle(&esp2, 1, 2))
  81.       return FAIL;
  82.  
  83.    ESP_Reset(&esp1);
  84.    ESP_GetSelfTestResults(&esp1, &rom_rev, &test_results);
  85.    if (rom_rev > 0x0F || test_results > 0x20) {
  86.       printf("ESP port address incorrect or no ESP found!\n");
  87.       return FAIL;
  88.       }
  89.  
  90.    printf("ESP Information report\n\n");
  91.    printf("Firmware revision %d.00.\n", rom_rev);
  92.    DisplayAttributes(test_attrs,NUM_TEST_ATTRS,test_results);
  93.    if (!(dips=ESP_GetNormalModeAddrSwitch(&esp1))) {
  94.       printf("No additional info for MCA-bus card\n");
  95.       return OK;
  96.       }
  97.  
  98.    printf("\nDIP switch settings indicate\n");
  99.    printf("Port 1:  UART address is %XH, IRQ level %d\n",
  100.       esp_uart_addr[dips & 0x07], esp_irq[dips & 0x07]);
  101.    dips >>= 4;
  102.    printf("Port 2:  UART address is %XH, IRQ level %d\n",
  103.       esp_uart_addr[dips & 0x07], esp_irq[dips & 0x07]);
  104.  
  105.    ESP_GetMode(&esp1, &def_mode, &cur_mode);
  106.    printf("\nPort 1 Current Mode Attributes:\n");
  107.    DisplayAttributes(mode_attrs, NUM_MODE_ATTRS, cur_mode);
  108.  
  109.    ESP_GetMode(&esp2, &def_mode, &cur_mode);
  110.    printf("\nPort 2 Current Mode Attributes:\n");
  111.    DisplayAttributes(mode_attrs, NUM_MODE_ATTRS, cur_mode);
  112.  
  113.    printf("\nPort 1 Bytes waiting to be read from RX Buffer: %d\n",
  114.         ESP_GetRXBytesAvail(&esp1));
  115.    printf("Port 1 Bytes available to be written in TX Buffer: %d\n",
  116.         ESP_GetTXSpaceAvail(&esp1));
  117.    printf("\nPort 2 Bytes waiting to be read from RX Buffer: %d\n",
  118.         ESP_GetRXBytesAvail(&esp2));
  119.    printf("Port 2 Bytes available to be written in TX Buffer: %d\n",
  120.         ESP_GetTXSpaceAvail(&esp2));
  121.    return OK;
  122. }
  123.  
  124.  
  125.  
  126.  
  127. void DisplayAttributes(attr_ptr, attr_count, source_info)
  128. struct attr_list *attr_ptr;
  129. short attr_count;
  130. short source_info;
  131. {
  132.    int i;
  133.    char *use_str;
  134.    for (i=0; i<attr_count; i++)
  135.       {
  136.       if (attr_ptr[i].attr_val & source_info)
  137.          use_str = attr_ptr[i].attr_true;
  138.       else
  139.          use_str = attr_ptr[i].attr_false;
  140.       printf("\t%s.\n",use_str);
  141.       }
  142. }
  143.